'use strict';
let reg = /BV.{10}/;

const Service = require('egg').Service;

class JiexiBvService extends Service {
  async regular(res) {
    let str = res.message;
    return reg.test(str);
  }

  async jiexi(res) {
    let sendMsg = this.ctx.service.sendMsg;
    let id = res.message.match(reg);
    id = parseInt(id[1]);
    let result = await this.ctx.curl(`http://api.bilibili.com/x/web-interface/view?bvid=${id}`, {
            contentType: 'json'
        });
    result = JSON.parse(result.data.toString());
    sendMsg.sendToGroup({
      id: res.group_id,
      msg: `[CQ:image,file=${result.data.pic}]\n\n${result.data.title}\n\n简介：\n${result.data.desc}\n\n播放量：${result.data.stat.view}\n弹幕数：${result.data.stat.danmaku}\n获赞数：${result.data.stat.like}\n投币数：${result.data.stat.coin}\n收藏数：${result.data.stat.favorite}\n\n视频链接：https://www.bilibili.com/video/${id}`
    })

  }
}

module.exports = JiexiBvService;